home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
music
/
eked-m1.zoo
/
src
/
gm
/
gem_man.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-19
|
8KB
|
278 lines
/*
* EKED-M1 : Editor for Korg M1 synth; gem_man.c : GEM extensions
* Copyright (C) 1995 Steven M. Eker (Steven.Eker@brunel.ac.uk)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stddef.h>
#include <osbind.h>
#include <gemfast.h>
#include <aesbind.h>
#include <vdibind.h>
#include "gem_man.h"
static int draw_button(PARMBLK *pb);
MFDB screen;
GRECT desk;
int char_w;
int char_h;
int nr_planes;
USERBLK gm_button = {(void *) draw_button, 0};
int gm_handle;
static MFDB button = {0, 16, 16, 1, 0, 1, 0, 0, 0};
static MFDB button_sel = {0, 16, 16, 1, 0, 1, 0, 0, 0};
static MFDB check = {0, 16, 16, 1, 0, 1, 0, 0, 0};
static MFDB check_sel = {0, 16, 16, 1, 0, 1, 0, 0, 0};
static int work_in[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2};
static int work_out[57];
static int phys_handle;
static int roll_flag = R_ROLL;
void gm_init()
{
static int but16[] = {
0x0000, 0x0000, 0x03c0, 0x0c30, 0x1008, 0x1008, 0x2004, 0x2004,
0x2004, 0x2004, 0x1008, 0x1008, 0x0c30, 0x03c0, 0x0000, 0x0000
};
static int but16_sel[] = {
0x0000, 0x0000, 0x03c0, 0x0c30, 0x1008, 0x13c8, 0x27e4, 0x27e4,
0x27e4, 0x27e4, 0x13c8, 0x1008, 0x0c30, 0x03c0, 0x0000, 0x0000
};
static int but8[] = {
0x07e0, 0x1818, 0x2004, 0x2004, 0x2004, 0x1818, 0x07e0, 0x0000
};
static int but8_sel[] = {
0x07e0, 0x1818, 0x23c4, 0x27e4, 0x23c4, 0x1818, 0x07e0, 0x0000
};
static int chk16[] = {
0x0000, 0x0000, 0x3ffc, 0x2004, 0x2004, 0x2004, 0x2004, 0x2004,
0x2004, 0x2004, 0x2004, 0x2004, 0x2004, 0x3ffc, 0x0000, 0x0000
};
static int chk16_sel[] = {
0x0000, 0x0000, 0x3ffc, 0x300c, 0x2814, 0x2424, 0x2244, 0x2184,
0x2184, 0x2244, 0x2424, 0x2814, 0x300c, 0x3ffc, 0x0000, 0x0000
};
static int chk8[] = {
0x3ffc, 0x2004, 0x2004, 0x2004, 0x2004, 0x2004, 0x3ffc, 0x0000
};
static int chk8_sel[] = {
0x3ffc, 0x381c, 0x2664, 0x2184, 0x2664, 0x381c, 0x3ffc, 0x0000
};
int point[4];
appl_init();
work_in[0] = Getrez() + 2;
phys_handle = graf_handle(&char_w, &char_h, &desk.g_w, &desk.g_h);
wind_get(DESK, WF_WORKXYWH, &desk.g_x, &desk.g_y, &desk.g_w, &desk.g_h);
gm_handle = gm_opnvwk();
GM_AES2VDI(point, &desk);
vs_clip(gm_handle, 1, point);
vsl_udsty(gm_handle, 0xAAAA);
vsl_type(gm_handle, 7);
vq_extnd(gm_handle, 1, work_out);
nr_planes = work_out[4];
if(char_h < 16){
button.fd_addr = (long) but8;
button_sel.fd_addr = (long) but8_sel;
button.fd_h = 8;
button_sel.fd_h = 8;
check.fd_addr = (long) chk8;
check_sel.fd_addr = (long) chk8_sel;
check.fd_h = 8;
check_sel.fd_h = 8;
}
else{
button.fd_addr = (long) but16;
button_sel.fd_addr = (long) but16_sel;
check.fd_addr = (long) chk16;
check_sel.fd_addr = (long) chk16_sel;
}
mg_init();
}
void gm_exit()
{
mg_exit();
gm_clsvwk(gm_handle);
appl_exit();
}
int gm_opnvwk()
{
int handle = phys_handle;
v_opnvwk(work_in, &handle, work_out);
return handle;
}
void gm_xorbox(GRECT *box)
{
int point[4];
vswr_mode(gm_handle, MD_XOR);
point[0] = box->g_x + 1;
point[2] = box->g_x + box->g_w - 2;
point[1] = point[3] = box->g_y;
v_pline(gm_handle, 2, point);
point[1] = point[3] = box->g_y + box->g_h - 1;
v_pline(gm_handle, 2, point);
point[1] = box->g_y + 1;
point[3] = box->g_y + box->g_h - 2;
point[0] = point[2] = box->g_x;
v_pline(gm_handle, 2, point);
point[0] = point[2] = box->g_x + box->g_w - 1;
v_pline(gm_handle, 2, point);
}
static int draw_button(PARMBLK *pb)
{
static int pens[] = {BLACK, WHITE};
static int points[8];
static GRECT rect;
MFDB *b;
rect = *((GRECT *) &(pb->pb_x));
if(intersect((GRECT *) &(pb->pb_xc), &rect)){
GM_AES2VDI(points + 4, &rect);
points[0] = rect.g_x - pb->pb_x;
points[1] = rect.g_y - pb->pb_y;
points[2] = points[0] + points[6] - points[4];
points[3] = points[1] + points[7] - points[5];
if(((pb->pb_tree)[pb->pb_obj].ob_type >> 8) == 1)
b = (pb->pb_currstate & SELECTED) ? &button_sel : &button;
else
b = (pb->pb_currstate & SELECTED) ? &check_sel : ✓
vrt_cpyfm(gm_handle, 1, points, b, &screen, pens);
}
return 0;
}
int gm_opaque(OBJECT *tree, int ob)
{
int old, t;
while(t = tree[ob].ob_type, (t == G_STRING || t == G_IMAGE || t == G_IBOX)){
do{
old = ob;
ob = tree[ob].ob_next;
if(ob == -1)
return old;
}while(tree[ob].ob_tail != old);
}
return ob;
}
int gm_roll_mode(int mode)
{
if(mode >= 0 && mode <= 2)
roll_flag = mode;
return roll_flag;
}
int gm_roll(OBJECT *tree, int ob, int value, int min, int max,
UPDATE_FUNC_PTR update, REDRAW_FUNC_PTR redraw)
{
int old_val, t, m_x, m_y, old_x, old_y, m_state, k_state, old_m_state, speed;
long delay;
GRECT rect;
graf_mkstate(&old_x, &old_y, &old_m_state, &k_state);
if(old_m_state == 0 || (tree[ob].ob_state & DISABLED))
return value;
wind_update(BEG_MCTRL);
objc_offset(tree, ob, &rect.g_x, &rect.g_y);
rect.g_w = tree[ob].ob_width;
rect.g_h = tree[ob].ob_height;
(void) intersect(&desk, &rect);
GM_BOUND_FIX(value, min, max); /* make sure value in range */
(*update)(tree + ob, value);
tree[ob].ob_state |= SELECTED;
(*redraw)(tree, ob, &rect);
if(roll_flag == R_ROLL){
speed = 200 / (max - min); /* 200 pixels for full range */
GM_BOUND_FIX(speed, 4, 16); /* but within sensible limits */
old_val = value;
for(;;){
graf_mkstate(&m_x, &m_y, &m_state, &k_state);
if(m_state == 0)
break;
if(m_state == old_m_state){
t = old_val + ((m_x - old_x) + (m_y - old_y)) / speed;
if(t > max)
t = max;
else if(t < min)
t = min;
if(value != t){
value = t;
(*update)(tree + ob, t);
(*redraw)(tree, ob, &rect);
}
}
else{
old_x = m_x;
old_y = m_y;
old_val = value;
}
}
}
else{
delay = 400;
for(;;){
evnt_timer(delay);
graf_mkstate(&m_x, &m_y, &m_state, &k_state);
if(m_state == 0)
break;
if(roll_flag == R_LEFTUP)
m_state ^= 3;
if(m_state == 1)
t = value - (value > min);
else if(m_state == 2)
t = value + (value < max);
else
continue;
if(value != t){
value = t;
(*update)(tree + ob, t);
(*redraw)(tree, ob, &rect);
}
if(delay > 40)
delay -= 20;
}
}
tree[ob].ob_state &= ~SELECTED;
(*redraw)(tree, ob, &rect);
wind_update(END_MCTRL);
return value;
}
int intersect(GRECT *r1, GRECT *r2)
{
int x, y;
x = MAX(r1->g_x, r2->g_x);
y = MAX(r1->g_y, r2->g_y);
r2->g_w = MIN(r1->g_x + r1->g_w, r2->g_x + r2->g_w) - x;
r2->g_h = MIN(r1->g_y + r1->g_h, r2->g_y + r2->g_h) - y;
r2->g_x = x;
r2->g_y = y;
return (r2->g_w > 0) && (r2->g_h > 0);
}